package com.gao.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.gao.entity.ShebeiEntity;
import com.gao.service.ShebeiService;
import com.gao.common.utils.PageUtils;
import com.gao.common.utils.R;


/**
 * @author gao
 * @email sunlightcs@gmail.com
 * @date 2021-03-14 20:52:23
 */
@RestController
//vue跨越问题解决
@CrossOrigin
@RequestMapping("shebei")
public class ShebeiController {
    @Autowired
    private ShebeiService shebeiService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = shebeiService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/ok")
    public String ok(){
        return "kokokokok";
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        ShebeiEntity shebei = shebeiService.getById(id);

        return R.ok().put("shebei", shebei);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ShebeiEntity shebei) {
        shebeiService.save(shebei);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ShebeiEntity shebei) {
        shebeiService.updateById(shebei);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        shebeiService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}

